/**
 *  Copyright (C) 2006 zhangbo (freeeob@gmail.com)
 *
 *  This product is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1 of the License, or
 *  (at your option) any later version.
 * 
 *  This product is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 *
 *  author:zhangbo
 *  Email:jsjava@gmail.com
 */

/**
 * constructor
 */ 
function PhotoAlbum(imgObjId){
	this.jsjava_class="jsorg.eob.component.album.PhotoAlbum";	
	this.renders=new Array();
	this.pid=imgObjId;
	this.pointer=0;
}

PhotoAlbum.ONCE_MODE=0;
PhotoAlbum.LOOP_MODE=1;

/**
 * Regist the specified album instance
 * @param albumObj
 */ 
PhotoAlbum.registry=function(albumObj){
	jsjava_photo_album_instances[albumObj.pid]=albumObj;
};

/**
 * Add a render
 * @param render
 */
PhotoAlbum.prototype.addRender=function(render){
	this.renders[this.renders.length]=render;
	render.setAlbum(this);
};

/**
 * Get a render
 * @param index
 */
PhotoAlbum.prototype.getRender=function(index){
	return this.renders[index];
};

/**
 * Get all renders
 */
PhotoAlbum.prototype.getAllRenders=function(){
	return this.renders;
};

/**
 * Display the album
 * @param mode play once or loop
 * @param span time span in millisecond
 */
PhotoAlbum.prototype.display=function(mode,span){	
	if(this.interval){
		return;
	}
    this.mode=mode;
    this.span=span;
    this.size=this.renders.length;
    jsjava_photo_album_display(this.pid,this.size);
    this.interval=setInterval("jsjava_photo_album_display('"+this.pid+"',"+this.size+")",span);
};

/**
 * Suspend the album
 */
PhotoAlbum.prototype.suspend=function(){	
	clearInterval(this.interval);
	this.interval=undefined;
};

/**
 * Restore the album
 */
PhotoAlbum.prototype.restore=function(){	
	this.display(this.mode,this.span);
};

/**
 * Skip to the specified frame
 */
PhotoAlbum.prototype.seek=function(index){	
	this.suspend();
	this.pointer=index;
	this.restore();
};

/**
 * Set user customed method
 * @param customRenderMethods
 */
PhotoAlbum.prototype.setCustomRenderMethod=function(customRenderMethod){
	this.customRenderMethod=customRenderMethod;
};

/**
 * Get user customed method
 */
PhotoAlbum.prototype.getCustomRenderMethod=function(){
	return this.customRenderMethod;
};

/**
 * Get the number of frames
 */
PhotoAlbum.prototype.getSize=function(){
	return this.renders.length;
};

/**
 * Get the current frame index
 */
PhotoAlbum.prototype.getPointer=function(){
	return this.pointer;
};

var jsjava_photo_album_instances=new Array();

function jsjava_photo_album_display(pid,size){
	var album=jsjava_photo_album_instances[pid];
	var imgObj=document.getElementById(pid);
	if(album.mode==PhotoAlbum.LOOP_MODE&&album.pointer==size){
		album.pointer=0;
	}
	album.renders[album.pointer++].execute(imgObj);
}